package com.bwhx.eruler.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bwhx.eruler.service.EtapeDecodeService;
import com.bwhx.eruler.util.ETypeDecrypt;
import com.bwhx.eruler.util.StringUtils;

 
@Controller
public class EtapeDecodeController extends BaseController {
	
 	@Autowired
	EtapeDecodeService service;
	
	@ResponseBody
	@RequestMapping(value = "/page.everyone.decoder.ashx")
	 public Map<String,Object> decoder( int[] value,String sn, String code) {
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		
		
		try{
			
			if(StringUtils.isEmpty(sn)||StringUtils.isEmpty(code)){
				 resultMap.put("status", "0");
				 resultMap.put("msg", "paramLost");
	              return resultMap;
			}
			
			int isLegal = service.isLegal(sn,code);
			if(isLegal==0){
				 resultMap.put("status", "0");
				 resultMap.put("msg", "matchingFailure");
	              return resultMap;
			}
 
  	        switch (value[0]) {
	            
	            case 0x4C:    //长度
	                // 解析数据
	                long nValueMM = ETypeDecrypt.Decrypt(value);
	                 resultMap.put("value", nValueMM);
	                resultMap.put("status", "1");
	                break;
	             
	        }		
		 
		} catch(Exception e){
			log.error(getTrace(e));
			resultMap.put("meg", "err!");
			resultMap.put("status", "0");
		}
		
	    return resultMap;  
	    
	  }
	
}
	

	 

